$(function () {
  $(".login").click(function () {
    let username = $("#username").val();
    let password = $("#password").val();
    console.log(username);
    console.log(password);
    $.ajax({
      url: "../server/login.php",
      type: "post",
      data: {
        username,
        password,
      },
      success(res) {
        let result = JSON.parse(res);
        console.log(result);
        if (result.code === 1) {
          toast("登录成功");

          $.cookie("userid", result.userid, { expires: 7 });
          $.cookie("user", username, { expires: 7 });
          history.go(-1);
        } else {
          toast("账号密码错误");
        }
      },
    });
  });
});
